class smx_cwebtools {
  require smx_os
  require smx_tomcat

  Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }

  file { '/vagrant/vagrant/download_cwebtools.sh':
    ensure => present,
    mode   => '0755', owner => root, group => root,
    source =>  "puppet:///modules/smx_cwebtools/download_cwebtools.sh",
  }

  exec { 'download_cwebtools':
    cwd       => '/vagrant/vagrant',
    command   => "/vagrant/vagrant/download_cwebtools.sh",
    timeout   => '1800', # half an hour, at most
    logoutput => true,
    require   => File['/vagrant/vagrant/download_cwebtools.sh'],
  }

  exec { 'sed add':
    command => "sed -i -e '/<\/Host>/i<Context docBase=\"/opt/cwebtools/pdftools\" path=\"\" reloadable=\"true\" debug=\"0\"\/>' /etc/tomcat/server.xml",
    path    => [ "/bin","/sbin","/usr/bin","/usr/sbin" ],
    unless  => "grep pdftools /etc/tomcat/server.xml",
  }

  file { '/lib64/libfauto_linux64.so':
    ensure  => link,
    target  => "/opt/cwebtools/libfauto_linux64.so",
    require => Exec['download_cwebtools'],
  }

  file { '/lib64/libicudata.so.55':
    ensure  => link,
    target  => "/opt/cwebtools/libicudata.so.55",
    require => Exec['download_cwebtools'],
  }

  file { '/lib64/libicui18n.so.55':
    ensure  => link,
    target  => "/opt/cwebtools/libicui18n.so.55",
    require => Exec['download_cwebtools'],
  }

  file { '/lib64/libicuuc.so.55':
    ensure  => link,
    target  => "/opt/cwebtools/libicuuc.so.55",
    require => Exec['download_cwebtools'],
  }
  file { '/opt/cwebtools/pdftools/WEB-INF/classes/log4j.properties':
    ensure  => present,
    mode    => '0755', owner => tomcat, group => tomcat,
    source  =>  "puppet:///modules/smx_cwebtools/log4j.properties",
    require => Exec['download_cwebtools'],
  }

  file { '/opt/cwebtools/pdftools/WEB-INF/classes/path.properties':
    ensure  => present,
    mode    => '0755', owner => tomcat, group => tomcat,
    source  =>  "puppet:///modules/smx_cwebtools/path.properties",
    require => Exec['download_cwebtools'],
  }
}
